package com.moehu.back.controller.admin;

import com.moehu.back.annotation.AdminRestController;
import com.moehu.back.annotation.UserLoginToken;
import com.moehu.back.model.OpusModel;
import com.moehu.back.model.ResultModel;
import com.moehu.back.model.UserModel;
import com.moehu.back.model.UserVerify;
import com.moehu.back.model.request.UserVerifyRequest;
import com.moehu.back.model.response.LoginResponseModel;
import com.moehu.back.model.response.PagingResponseModel;
import com.moehu.back.model.response.admin.UserLoginModel;
import com.moehu.back.service.impl.UserServiceImpl;
import com.moehu.back.service.impl.admin.AdminUserServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping(value = "/user")
@AdminRestController
@Api(tags = "【管理后台】User 用户相关接口")
public class AdminUserController {

    @Autowired
    private AdminUserServiceImpl adminUserService;

    @Autowired
    private UserServiceImpl userService;

    @ApiOperation(value="管理后台用户登录", notes="用户登录成功后，接口会返回token字段，需要前端自己存储，并在请求头 token 中携带")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "admin_user_name", value = "管理员登录用户名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "admin_user_pwd", value = "管理员登录密码", required = true, dataType = "String")})
    @PostMapping("/Login")
    public ResultModel<LoginResponseModel<UserLoginModel>> Login(@RequestBody UserLoginModel User) {
        return adminUserService.login(User);
    }


    @ApiOperation(value="管理后台用户注册", notes="管理后台用户注册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "admin_user_name", value = "管理员用户名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "admin_user_pwd", value = "管理员密码", required = true, dataType = "String")})
    @PostMapping("/Reg")
    public ResultModel Reg(@RequestBody UserLoginModel User) {
        return adminUserService.reg(User);
    }


    @UserLoginToken
    @ApiOperation(value="【管理后台】获取头像，签名，昵称审核的列表", notes="获取头像，签名，昵称审核的列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_id", value = "用户id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "user_verify_status", value = "审核状态：0等待审核，1 审核通过， -1 审核拒绝", required = true, dataType = "Number"),
            @ApiImplicitParam(name = "type", value = "需要请求的数据类型，取值：avatar（头像），nickname（昵称），signature（签名）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "page", value = "请求的页数", required = true, dataType = "Number"),
            @ApiImplicitParam(name = "count", value = "每页作品数，默认15", required = true, dataType = "Number", defaultValue="15"),
    })
    @PostMapping("/UserVerifyList")
    public ResultModel<PagingResponseModel<List<UserVerify>>> EditUserInfo(@RequestBody UserVerifyRequest user) {
        return userService.UserVerifyList(user);
    }

    @UserLoginToken
    @ApiOperation(value="【管理后台】对 [UserVerifyList] 列表进行审核", notes="对 [UserVerifyList] 列表进行审核")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_verify_id", value = "审核列表的id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "user_verify_status", value = "审核状态：1 通过审核， -1 审核拒绝", required = true, dataType = "Number"),
    })
    @PostMapping("/UserReview")
    public ResultModel<String> UserReview(@RequestBody Map<String, Integer> params) {
        return userService.UserReview(params);
    }

    @UserLoginToken
    @ApiOperation(value="【管理后台】查看接口 [UserVerifyList] 的详情", notes="查看接口 [UserVerifyList] 的详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user_verify_id", value = "用户昵称", required = true, dataType = "Number")
    })
    @PostMapping("/UserItemInfo")
    public ResultModel<UserModel> UserItemInfo(@RequestBody UserVerify user) {
        return userService.UserItemInfo(user);
    }
}
